export const JUST_NOW = 3000; //3s内
export const IN_SECOND = 1000 * 60; //一分钟
export const IN_MINUTE = 1000 * 60 * 60; //一小时
export const IN_HOUR = 1000 * 60 * 60 * 12; //12小时
export const IN_DAY = 1000 * 60 * 60 * 24 * 1; //1天
export const IN_MONTH = 1000 * 60 * 60 * 24 * 30; //1个月

export function updateTimeShow(time) {
  let localTime = new Date(); //当前系统时间
  // console.log(localTime);
  let createTime = new Date(time); //消息创建时间
  // console.log(createTime);
  let diff = localTime - createTime;
  // console.log(diff);
  if (diff <= JUST_NOW) {
    return "刚刚";
  } else if (diff <= IN_SECOND) {
    return "1分钟内";
  }else if (diff <= IN_MINUTE) {
    return parseInt(diff / IN_SECOND) + "分钟前";
  } else if (diff <= IN_MINUTE) {
    return parseInt(diff / IN_MINUTE) + "小时前";
  }else if (diff <= IN_HOUR) {
    const list = createTime.toString().split(" ");
    const lastIndex = list[4].lastIndexOf(":");
    const realtime = list[4].toString().substring(0, lastIndex);
    const hour=realtime.split(":")[0];
    let str = "";
    if(hour < 12){
        str = "上午";
    }else if(hour == 12){
        str = "中午";
    }else{
        str = "下午";
    }
    return str+" "+realtime;
  }if (diff < IN_DAY) {
    return "昨天";
  }else if (diff < IN_DAY * 7) {
    const t = createTime.toString().slice(0, 3);
    switch (t) {
      case "Mon":
        return "星期一";
      case "Tue":
        return "星期二";
      case "Wed":
        return "星期三";
      case "Thu":
        return "星期四";
      case "Fri":
        return "星期五";
      case "Sat":
        return "星期六";
      case "Sun":
        return "星期日";
    }
  } else if (diff < IN_MONTH * 24) {
    const list = createTime.toString().split(" ");
    const month = list[1];
    var realtime = "";
    if (diff < IN_MONTH) {
      realtime = getNumberMonth(month);
    } else {
      realtime = list[3] + "-" + getNumberMonth(month);
    }
    return realtime + "-" + list[2];
  }else{
      return ""
  }
}

export function getNumberMonth(month) {
  switch (month) {
    case "Jan":
      return "01";
    case "Feb":
      return "02";
    case "Mar":
      return "03";
    case "Apr":
      return "04";
    case "May":
      return "05";
    case "Jun":
      return "06";
    case "Jul":
      return "07";
    case "Aug":
      return "08";
    case "Sept":
      return "09";
    case "Oct":
      return "10";
    case "Nov":
      return "11";
    case "Dec":
      return "12";
  }
}
